package com.lucenly.spell.view.dialog

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.lucenly.spell.R
import com.moregold.mvvmlib.ext.ext_doubleClick

class PayDialog(context:Context) : Dialog(context, R.style.DialogStyle){
    var ivZfb : ImageView? = null
    var ivWx : ImageView? = null
    var ivYe : ImageView? = null

    init {
        val view = layoutInflater.inflate(R.layout.dialog_pay,null)
        setContentView(view)
        setCanceledOnTouchOutside(false)
        val ivClose = view.findViewById<ImageView>(R.id.ivClose)
        val tvSure = view.findViewById<TextView>(R.id.tvSure)
        ivZfb = view.findViewById(R.id.ivZfb)
        ivWx = view.findViewById(R.id.ivWx)
        ivYe = view.findViewById(R.id.ivYe)
        ivClose.ext_doubleClick {
            dismiss()
        }
        tvSure.ext_doubleClick {
            val resultDialog = PayResultDialog(context)
            resultDialog.show()
            dismiss()
        }
        ivZfb?.ext_doubleClick {
            setSelect(ivZfb)
        }
        ivWx?.ext_doubleClick {
            setSelect(ivWx)
        }
        ivYe?.ext_doubleClick {
            setSelect(ivYe)
        }
        val window = window
        if (window != null) {
            val params = window.attributes
            params.width = LinearLayout.LayoutParams.MATCH_PARENT
            params.height = LinearLayout.LayoutParams.WRAP_CONTENT
            params.gravity = Gravity.BOTTOM
            window.attributes = params
        }
    }
    private fun setSelect(imageView:ImageView?){
        ivZfb?.setImageResource(R.mipmap.wxz)
        ivWx?.setImageResource(R.mipmap.wxz)
        ivYe?.setImageResource(R.mipmap.wxz)
        imageView?.setImageResource(R.mipmap.xz)
    }
}